const randomArray = {
    arrList:[
        {name:"胡颖(组长)",group:"一组"},
        {name:"何润宏",group:"一组"},
        {name:"李志豪",group:"一组"},
        {name:"候华雨",group:"一组"},
        {name:"谢凯伦",group:"一组"},
        {name:"张家顺",group:"一组"},
        {name:"吴旭",group:"一组"},
        {name:"姚宗宝(组长)",group:"二组"},
        {name:"于贵",group:"二组"},
        {name:"徐溢洪",group:"二组"},
        {name:"陈立果",group:"二组"},
        {name:"张申德",group:"二组"},
        {name:"张也",group:"二组"},
        {name:"周斯佳",group:"二组"},
        {name:"刘杨",group:"二组"},
        {name:"朱鹏富(组长)",group:"三组"},
        {name:"赵中",group:"三组"},
        {name:"颜苗",group:"三组"},
        {name:"谭诗颖",group:"三组"},
        {name:"叶彬",group:"三组"},
        {name:"邓俊豪",group:"三组"},
        {name:"陈仲",group:"三组"},
        {name:"蒋超琼(组长)",group:"四组"},
        {name:"温鑫",group:"四组"},
        {name:"夏怀球",group:"四组"},
        {name:"刘帅",group:"四组"},
        {name:"朱澳",group:"四组"},
        {name:"高丽",group:"四组"},
        {name:"李虎",group:"四组"},
        {name:"钱宇亮",group:"四组"},
        {name:"孔德庆(组长)",group:"五组"},
        {name:"陈洁钰",group:"五组"},
        {name:"张家明",group:"五组"},
        {name:"徐涵",group:"五组"},
        {name:"沈晟平",group:"五组"},
        {name:"张志翔",group:"五组"},
        {name:"应子洋",group:"五组"},
        {name:"吴燚波",group:"五组"},
        {name:"凌佳晨",group:"五组"}
    ],
    prize:[
        "在你洗澡时，有一个非常丑的异性冲了进来，你会怎么样(实话实说，希望不要采用极端手法",
        "你有没有钟意的人?是谁",
      　"你的初恋是几岁",
      　"你的初恋对象是谁",
      　"你的初吻是几岁，被谁夺取的",
      　"你亲吻过多少人",
      　"在现场所有人中，你看哪位异性同学最舒服",
      　"你第一个喜欢的异性叫什么名字",
      　"如果再给你一个机会，回到高中时代，最想对哪位异性说哪些话",
      　"谈过几次恋爱",
      　"每天睡觉前都会想起的人是谁",
      　"让你一直念念不忘的一位异性的名字?原因",
      　"你最愿意和在场哪个异性私奔",
      　"你觉得在座那位异性的嘴唇看起来最想Kiss",
      　"你想和在场的哪一位玩大冒险",
      　"你觉得你曾经喜欢的人和在座哪个人最像",
      　"在场哪一位异性对你说我喜欢你，你会最开心",
      　"如果时间能倒流你希望回到哪一时间，为什么",
      　"你是否幻想过或希望和你喜欢的人做那些事?只用回答有或没有(如实回答",
      　"我在你眼里什么样?(可以是上一位玩家，由主持人决定)"
    ],
    // 随机打乱数组
    stochastic:function(){
        let newList = new Array();
        let key = 0;
        while(this.arrList.length>0){
             key = Math.floor(Math.random() * this.arrList.length);
             newList.push(this.arrList[key])
             this.arrList.splice(key,1)
        } 
        return newList
    },
    color:function(a){
        let r = Math.floor(Math.random() * 255);
        let g = Math.floor(Math.random() * 255)
        let b = Math.floor(Math.random() * 255)
        let ar
        if(a===undefined){
            ar = Math.random()
        }else{
            ar = a
        }
        
        console.log(r,g,b,a)
        return 'rgba('+ r +','+ g +','+ b +','+ ar +')';
    },
    // 初始化页面
    init:function(){
        let oAward = document.getElementById('award')
        let oUserList = oAward.getElementsByClassName('userlist');
        let oOutOfOrder = oAward.getElementsByClassName('out-of-order');
        let oOn = oAward.getElementsByClassName('on');
        let intNum = oAward.getElementsByClassName('num');
        let oThewinners = oAward.getElementsByClassName('thewinners');
        let oPrize = oAward.getElementsByClassName('prize');
        let self = this;
        let newList = this.stochastic();
        let closeTimer = null;
        function initDOM(){
            oUserList[0].innerHTML = '';
            newList.forEach(function(value){
                // oUserList[0].innerHTML += '<li>'+value.group +' - '+ value.name+'</li>'
                let li = document.createElement('li');
                let textNode = document.createTextNode(value.group+' - '+value.name);
                li.appendChild(textNode)
                li.style.cssText = 'background:'+self.color(1)+';color:#eee';
                oUserList[0].appendChild(li)
            });
            return self
        }
        function arrayReset(){
            self.arrList = newList;
            newList = self.stochastic();
        }
        initDOM()
        oOutOfOrder[0].onclick=function(){
            oThewinners[0].innerHTML = '';
            arrayReset()
            initDOM()
        }
        oOn[0].onclick=function(){
            let n = 0;
            closeTimer = setInterval(function(){
                n++;
                arrayReset()
                initDOM()
                if(n>=newList.length){
                    clearInterval(closeTimer)
                    oThewinners[0].innerHTML = '';
                    let thewinners = [];
                    for (let index = 0; index < intNum[0].value; index++) {
                       let int = Math.floor(Math.random() * newList.length)
                       const el = newList[int];
                       thewinners.push(el)
                       if(newList.length>=intNum[0].value){
                          newList.splice(int,1)
                       }else{
                         oThewinners[0].innerHTML = '当前奖池内人数小于中奖者名单，请重置页面或减少中奖者人数'
                         return false
                        }
                    }
                    thewinners.forEach(function(value){
                        let prizeInt = Math.floor(Math.random() * self.prize.length)
                        let span = document.createElement('span')
                        let textNode = document.createTextNode(value.group+' - '+value.name);
                        span.appendChild(textNode)
                        oPrize[0].innerHTML = self.prize[prizeInt]
                        oThewinners[0].appendChild(span)
                    })
                } 
            }, 30);
        }
        return this
    }

}